/********************************************************/
/*	Author:		gong_libin			*/
/*	Date:		2017_11_01			*/
/*	File:		CmProJsnTest.cpp		*/
/********************************************************/

#include "CmProJsn.h"

int main(int argc, char* argv[])
{
	CCmProJsn CJsn;
	CMADXINFO_S stAdInfo;
	CMADXINFO_S* pstAdInfo = NULL;
	char szMsg[] = "{\"appId\":\"CmAppId\",\"categoryIds\":\"1,2,3,4,5,6,\",\"channelId\":\"CmChannelId\",\"contextId\":\"CmContextId\",\"creativeView\":1,\"developerId\":\"CmDeveloperId\",\"exhibitId\":\"CmExhibitionId\",\"gps\":\"36.00929,108.2394823\",\"imei\":\"CmUserImei\",\"ip\":\"192.168.100.200\",\"mac\":\"08:00:27:9a:2d:82\",\"maxHeight\":\"300\",\"maxWidth\":\"1280\",\"minPrice\":800,\"scaling\":\"1.6\",\"type\":\"1\",\"uagent\":\"Mozilla/5.0 (Windows NT 10.0;WOW64) AppleWebKit/537.36(KHTML, like Gecko) Chrom/60.0.31112.78 Safari/537.36\",\"uId\":\"CmUserId\",\"version\":1,\"adSourceId\":2,\"SupervisoryUrl\":\"http://www.supervisory_url.com\",\"clickUrl\":\"http://www.click_through_url.com\",\"creativeTitle\":\"creativetitle\",\"creativeType\":1,\"creativeId\":\"100\",\"adverId\":\"adverId\",\"destinationUrl\":\"http://www.destination.com\",\"extendData\":\"hello adx\",\"category\":\"3\",\"maxPrice\":850,\"adResponseCode\":1001,\"adBillingMethod\":2}";

	// request
	stAdInfo.m_uiVer = 1;
	stAdInfo.m_uiDsp = 2;
	stAdInfo.m_CCtxtid = "CmContextId";
	stAdInfo.m_CIP = "192.168.100.200";
	stAdInfo.m_CUid = "CmUserId";
	stAdInfo.m_CMac = "08:00:27:9a:2d:82";
	stAdInfo.m_CGps = "36.00929,108.2394823";
	stAdInfo.m_CImei = "CmUserImei";
	stAdInfo.m_CUa = "Mozilla/5.0 (Windows NT 10.0;WOW64) AppleWebKit/537.36(KHTML, like Gecko) Chrom/60.0.31112.78 Safari/537.36";
	stAdInfo.m_CDid = "CmDeveloperId";
	stAdInfo.m_CAid = "CmAppId";
	stAdInfo.m_CEid = "CmExhibitionId";
	stAdInfo.m_CCid = "CmChannelId";
	stAdInfo.m_CCats = "1,2,3,4,5,6,";
	stAdInfo.m_CType = "1";
	stAdInfo.m_CWidth = "1280";
	stAdInfo.m_CHeight = "300";
	stAdInfo.m_CScaling = "1.6";
	stAdInfo.m_uiCrtView = 1;
	stAdInfo.m_uiMinPrice = 800;
	// response
	stAdInfo.m_CAdvId = "adverId";
	stAdInfo.m_CDesUrl = "http://www.destination.com";
	stAdInfo.m_CClkUrl = "http://www.click_through_url.com";
	stAdInfo.m_CSupUrl = "http://www.supervisory_url.com";
	stAdInfo.m_CExtend = "hello adx";
	stAdInfo.m_CCategory = "3";
	stAdInfo.m_uiCode = 1001;
	stAdInfo.m_uiMethod = 2;
	stAdInfo.m_uiMaxPrice = 850;
	stAdInfo.m_CCrtId  = "100";
	stAdInfo.m_CCrtTitle = "creative title";
	stAdInfo.m_uiCrtType = 1;
	std::cout << "CmProtoSerialize:\n" << CJsn.CmProtoSerialize(&stAdInfo) << std::endl;
	
	if (NULL != (pstAdInfo = CJsn.CmProtoDeserialize(szMsg))) {
		CJsn.CmProtoAdxInfoPrint();
	}
	else {
		CM_PRINT("Failed to CmProtoDeserialize\n");
	}

	return CM_SUCCESS;
}
